﻿using Plexi.Science;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Plexi
{
	/// <summary>Stores data about a moved rock, also saveable.</summary>
	public class RealRockInfo
	{
		/// <summary>This is the version of the rock info serialization method, not the version of the mod!</summary>
		public const string CurrentVersion = "1.1";

		public int BodyIndex { get; set; }
		public int IndexInCell { get; set; }
		public int Cx { get; set; }
		public int Cy { get; set; }
		public RockData Data { get; set; }
		public float Scale { get; set; }
		public int TextureIndex { get; set; }

		/// <summary>for use with Equals() in saving (GroupBy)</summary>
		public Vector2 GetCell()
		{
			return new Vector2(Cx, Cy);
		}

		/// <summary>Returns the mass of the rock, in tons. Also sets the Mass of the Data property.</summary>
		public float CalculateMass()
		{
			Data.Mass = (SurfaceRockSpawner.BaseRockVolume * Scale * Data.Type.SpecificWeight) / 1000f;
			return Data.Mass;
		}

		public override bool Equals(object obj)
		{
			RealRockInfo other = obj as RealRockInfo;
			return other != null &&
				BodyIndex == other.BodyIndex && Cx == other.Cx && Cy == other.Cy && IndexInCell == other.IndexInCell;
		}
	}
}
